package com.itheima.case2.dao;


import com.itheima.case2.pojo.po.User;
import com.itheima.case2.pojo.vo.AddUser;
import com.itheima.case2.pojo.vo.QueryPageBean;
import com.itheima.case2.pojo.vo.UpdateUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    //1.分页查询
    //1.1分页查询页码
    List<User> queryUserByPage(QueryPageBean pb);

    //1.2查询的总条数
    @Select("select count(*) from t_user")
    long queryAllByPage();


    //  2.修改用户
    //2.1更新用户信息
    @Update("update t_user set username=#{username},password=#{password},email=#{email} where id=#{id}")
    void updateUser(UpdateUser user);
    //2.2删除用户id
    @Delete("delete from t_user_role where user_id=#{id}")
    void deleteUserById(@Param("id") Integer id);
    //2.3插入更新的信息
    void insertUser(@Param("uid") Integer id, @Param("rids") List<String> roleIds);

    //3.添加用户
    @Insert("insert into t_user values (null,#{username},#{email},#{password},#{remark},'2021-06-22 09:09:43','2021-07-22 09:09:43')")
    //自增主键回填：将新插入数据的id放到添加用户的对象中
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void addUsers(AddUser user);
    //4.删除用户
    @Delete("delete from t_user where id=#{id};")
    void deleteUser(int id);
}
